﻿//using System;

//namespace LightCAD.MathLib
//{
//    internal static class MathUtils
//    {
//        /// <summary>
//        /// 点是否在矩形内
//        /// </summary>
//        internal static bool IsPointInRectangle(Vector2 point, Rectangle2 rect)
//        {
//            Vector2 rectLeftBottom = rect.leftBottom;
//            Vector2 rectRightTop = rect.rightTop;

//            if (point.x >= rectLeftBottom.x
//                && point.x <= rectRightTop.x
//                && point.y >= rectLeftBottom.y
//                && point.y <= rectRightTop.y)
//            {
//                return true;
//            }
//            else
//            {
//                return false;
//            }
//        }

//        /// <summary>
//        /// Cross window
//        /// https://yal.cc/rectangle-circle-intersection-test/
//        /// </summary>
//        internal static bool BoundingCross(Bounding bounding, Circle circle)
//        {
//            Vector2 nearestPntOnBound = new Vector2(
//                Math.Max(bounding.left, Math.Min(circle.center.x, bounding.right)),
//                Math.Max(bounding.bottom, Math.Min(circle.center.y, bounding.top)));

//            if (Vector2.Distance(nearestPntOnBound, circle.center) <= circle.radius)
//            {
//                double bdLeft = bounding.left;
//                double bdRight = bounding.right;
//                double bdTop = bounding.top;
//                double bdBottom = bounding.bottom;

//                return Vector2.Distance(new Vector2(bdLeft, bdTop), circle.center) >= circle.radius
//                    || Vector2.Distance(new Vector2(bdLeft, bdBottom), circle.center) >= circle.radius
//                    || Vector2.Distance(new Vector2(bdRight, bdTop), circle.center) >= circle.radius
//                    || Vector2.Distance(new Vector2(bdRight, bdBottom), circle.center) >= circle.radius;
//            }
//            else
//            {
//                return false;
//            }
//        }

//        /// <summary>
//        /// Cross window
//        /// https://yal.cc/rectangle-circle-intersection-test/
//        /// </summary>
//        internal static bool BoundingCross(Bounding bounding, Ellipse ellipse)
//        {
//            Vector2 nearestPntOnBound = new Vector2(
//                Math.Max(bounding.left, Math.Min(ellipse.center.x, bounding.right)),
//                Math.Max(bounding.bottom, Math.Min(ellipse.center.y, bounding.top)));

//            if (Vector2.Distance(nearestPntOnBound, ellipse.center) <= ellipse.radiusX
//                || Vector2.Distance(nearestPntOnBound, ellipse.center) <= ellipse.radiusY)
//            {
//                double bdLeft = bounding.left;
//                double bdRight = bounding.right;
//                double bdTop = bounding.top;
//                double bdBottom = bounding.bottom;

//                return Vector2.Distance(new Vector2(bdLeft, bdTop), ellipse.center) >= ellipse.radiusX
//                    || Vector2.Distance(new Vector2(bdLeft, bdBottom), ellipse.center) >= ellipse.radiusY
//                    || Vector2.Distance(new Vector2(bdRight, bdTop), ellipse.center) >= ellipse.radiusY
//                    || Vector2.Distance(new Vector2(bdRight, bdBottom), ellipse.center) >= ellipse.radiusY;
//            }
//            else
//            {
//                return false;
//            }
//        }

//        /// <summary>
//        /// 值是否在范围内
//        /// </summary>
//        internal static bool IsValueInRange(double value, double min, double max)
//        {
//            return value >= min && value <= max;
//        }

//        /// <summary>
//        /// 规整化弧度
//        /// 返回值范围:[0, 2*PI)
//        /// </summary>
//        internal static double NormalizeRadianAngle(double rad)
//        {
//            double value = rad % (2 * Utils.PI);
//            if (value < 0)
//                value += 2 * Utils.PI;
//            return value;
//        }

//        /// <summary>
//        /// Mirror matrix
//        /// </summary>
//        internal static Matrix3 MirrorMatrix(Line2 mirrorLine)
//        {
//            Vector2 lineDir = mirrorLine.direction;
//            Matrix3 matPos1 = Matrix3.Translate(-mirrorLine.startPoint);
//            double rotAngle = Vector2.SignedAngle(lineDir, new Vector2(1, 0));
//            Matrix3 matRot1 = Matrix3.Rotate(rotAngle);

//            Matrix3 mirrorMatX = new Matrix3(1, 0, 0, 0, -1, 0, 0, 0, 1);

//            Matrix3 matRot2 = Matrix3.Rotate(-rotAngle);
//            Matrix3 matPos2 = Matrix3.Translate(mirrorLine.startPoint);

//            return matPos2 * matRot2 * mirrorMatX * matRot1 * matPos1;
//        }

//    }
//}
